<template>
  <view class="mine-container" :style="{ height: `${windowHeight}px` }">
    <!--顶部个人信息栏-->
    <view class="header-section">
      <view class="flex padding justify-between">
        <view class="flex align-center">
          <view v-if="!avatar" class="cu-avatar xl round bg-white">
            <view class="iconfont icon-people text-gray icon"></view>
          </view>
          <image
            v-if="avatar"
            @click="handleToAvatar"
            :src="avatar"
            class="cu-avatar xl round"
            mode="widthFix"
          >
          </image>
          <view v-if="!name" @click="handleToLogin" class="login-tip">
            点击登录
          </view>
          <view v-else class="header_userInfo">
            <view class="user_name text-xxl">{{ name }}</view>
            <view class="user_tag flex align-center">
              <view>{{ userInfo.departmentTitle }}</view>
            </view>
          </view>
        </view>
      </view>
    </view>

    <view class="content-section">
      <view class="myListBox">
        <view
          class="list-cell list-cell-arrow"
          v-for="(item, index) in arr"
          @click="jump(`/pages/myOperation/index?repairType=${item.type}`)"
          :key="index"
        >
          <view class="menu-item-box">
            <view>{{ item.title }}</view>
          </view>
        </view>
        <!-- <view
          class="list-cell list-cell-arrow"
          @click="jump('/pages/changePassword/getCode/index')"
        >
          <view class="menu-item-box">
            <view>修改密码</view>
          </view>
        </view> -->
        <view class="list-cell">
          <view class="menu-item-box flex justify-between">
            <view>当前版本</view>

            <view style="color: #696969"> {{ config.appInfo.version }}</view>
          </view>
        </view>
      </view>
    </view>
    <button class="cu-btn block lg round outLoginBtn" @click="handleLogout">
      退出登录
    </button>
  </view>
</template>

<script>
import config from "./../../config";
import { mapState } from "vuex";
export default {
  data() {
    return {
      arr: [
        {
          title: "我的保养",
          type: 1,
        },
        {
          title: "我的报修",
          type: 2,
        },
        {
          title: "我的维修",
          type: 3,
        },
        {
          title: "我的出借",
          type: 4,
        },
        {
          title: "我的归还",
          type: 5,
        },
      ],
      config,
    };
  },
  computed: {
    ...mapState("user", ["userInfo", "name", "avatar"]),
    windowHeight() {
      return uni.getSystemInfoSync().windowHeight - 50;
    },
  },
  methods: {
    handleToLogin() {
      this.$tab.reLaunch("/pages/login/login");
    },
    handleToAvatar() {
      // this.$tab.navigateTo("/pages/mine/avatar/index");
    },
    handleLogout() {
      this.$modal.confirm("确定注销并退出系统吗？").then(() => {
        this.$store.dispatch("user/LogOut").then(() => {
          this.$tab.reLaunch("/pages/login/login");
        });
      });
    },
    jump(url) {
      this.$tab.navigateTo(url);
    },
  },
};
</script>

<style lang="scss">
page {
  background-color: #fff;
}

.mine-container {
  width: 100%;
  height: 100%;
  padding: 30upx;
  .header-section {
    padding: 15px;
    background-color: #3c96f3;
    color: white;
    border-radius: 20upx;

    .login-tip {
      font-size: 18px;
      margin-left: 10px;
    }
    .header_userInfo {
      margin-left: 40upx;
      .user_name {
        font-weight: 700;
      }
      .user_tag {
        font-size: 30upx;
        view {
          margin-right: 20upx;
          height: 54upx;
          line-height: 54upx;
          border: 1px solid #fff;
          padding: 0 20upx;
          border-radius: 27upx;
        }
      }
    }
    .cu-avatar {
      border: 2px solid #eaeaea;

      .icon {
        font-size: 40px;
      }
    }

    .user-info {
      margin-left: 15px;

      .u_title {
        font-size: 18px;
        line-height: 30px;
      }
    }
  }
  .content-section {
    position: relative;
    .list-cell {
      padding: 20upx 0;
    }
    .myListBox {
      font-size: 30upx;
      margin: 40upx 0;
    }
    .mine-actions {
      margin: 15px 15px;
      padding: 20px 0px;
      border-radius: 8px;
      background-color: white;

      .action-item {
        .icon {
          font-size: 28px;
        }

        .text {
          display: block;
          font-size: 13px;
          margin: 8px 0px;
        }
      }
    }
  }
  .outLoginBtn {
    color: #9f9f9f;
    background: #eeeeee;
  }
}
</style>
